import {createRouter, createWebHistory, RouteRecordRaw} from 'vue-router'
import Layout from '@/layout/index.vue'

// 扩展类型
type RouteConfig = RouteRecordRaw & { hidden?: boolean }; //hidden 是可选属性
export const constantRoutes: Array<RouteConfig> = [
    {
        path: '/redirect',
        component: Layout,
        hidden: true,
        children: [
            {
                path: '/redirect/:path(.*)',
                component: () => import('@/views/redirect.vue')
            }
        ]
    },
    {
        path: '/login',
        name: 'Login',
        component: () => import('@/views/loginRegister.vue'),
        hidden: true
    },
    {
        path: '/404',
        name: '404',
        component: () => import('@/views/404.vue'),
        hidden: true
    },
    {
        // vue2使用* vue3使用:pathMatch('*') 或者 :pathMatch('*')* 或者 :catchAll(.*)
        path: "/:pathMatch(.*)*",
        component: () => import('@/views/404.vue'),
        hidden: true
    },
    {
        path: '',
        component: Layout,
        redirect: '/home',
        children: [
            {
                path: '/home',
                component: () => import('@/views/home.vue'),
                name: 'Home',
                meta: {title: '首页', icon: 'HelpFilled', affix: true}
            }
        ]
    },
    {
        path: '/system/dictData',
        component: Layout,
        hidden: true,
        children: [
            {
                path: 'index/:dictId(\\d+)',
                component: () => import('@/views/system/dict/data.vue'),
                name: 'Data',
                meta: {title: '字典数据', activeMenu: "/system/dict"}
            }
        ]
    },
]

const router = createRouter({
    history: createWebHistory(),
    scrollBehavior: () => ({left: 0, top: 0}),// 刷新时，滚动条位置还原
    routes: constantRoutes
})

export default router
